ddns-scripts: refactor stop_section_processes()
authorPaul Donald <[email protected]>
Sat, 30 Nov 2024 15:26:27 +0000 (16:26 +0100)
committerFlorian Eckert <[email protected]>
Thu, 10 Apr 2025 07:34:38 +0000 (09:34 +0200)
Now a single xargs calls instead of grepping ps output (unreliable).

Signed-off-by: Paul Donald <[email protected]>
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh

index 5e157f30136cae0f450e76c91eedf7f61c7b3c90..ba1572ec676235d2c974cd1d221f45dcbc9cd04c 100644 (file)
@@ -204,15 +204,14 @@ start_daemon_for_all_ddns_sections()
 # stop sections process incl. childs (sleeps)
 # $1 = section
 stop_section_processes() {
-       local __PID=0
-       local __PIDFILE="$ddns_rundir/$1.pid"
-       [ $# -ne 1 ] && write_log 12 "Error calling 'stop_section_processes()' - wrong number of parameters"
+       local pid_file
+       pid_file="$ddns_rundir/$1.pid"
+       [ $# -ne 1 ] && write_log 12 "Error: 'stop_section_processes()' requires exactly one parameter"
 
-       [ -e "$__PIDFILE" ] && {
-               __PID=$(cat $__PIDFILE)
-               busybox ps | grep "^[\t ]*$__PID" >/dev/null 2>&1 && kill $__PID || __PID=0     # terminate it
+       [ -e "$pid_file" ] && {
+               xargs kill < "$pid_file" 2>/dev/null && return 1
        }
-       [ $__PID -eq 0 ] # report if process was running
+       return 0 # nothing killed
 }
 
 # stop updater script for all defines sections or only for one given